package com.epfresh.supplier.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.epfresh.api.global.AppActivity;
import com.epfresh.api.utils.LocalDisplay;
import com.epfresh.supplier.R;
import com.epfresh.supplier.view.tag.FlowLayout;
import com.epfresh.supplier.view.tag.TagAdapter;
import com.epfresh.supplier.view.tag.TagFlowLayout;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
 * Created by wzh on 16-7-25.
 */
public class ProductAddPackageMoreActivity extends AppActivity {



    private TagFlowLayout tagFlowLayout;



    private List<String> list = new ArrayList<>();

    private TagAdapter<String> tagAdapter;

    int tagW = -1;





    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        setContentView(R.layout.activity_product_add_package);
        toolbarTitle.setText("价格");
        ivBack.setVisibility(View.VISIBLE);
        tvBack.setVisibility(View.VISIBLE);

        rightbtn.setText("保存");

        rightbtn.setVisibility(View.VISIBLE);



        tagW = LocalDisplay.SCREEN_WIDTH_PIXELS - LocalDisplay.dp2px(4) * 10;
        tagW /= 4;

        tagFlowLayout = (TagFlowLayout) findViewById(R.id.t_tag);

        tagFlowLayout.setMaxSelectCount(1);
        tagAdapter = new TagAdapter<String>(list) {
            @Override
            public View getView(FlowLayout parent, int position, String s) {
                TextView tv = (TextView) LayoutInflater.from(ProductAddPackageMoreActivity.this).inflate(R.layout.tag,
                        parent, false);
                ViewGroup.LayoutParams lp = tv.getLayoutParams();
                lp.width = tagW;
                tv.setText(s);
                return tv;
            }
        };
        tagFlowLayout.setAdapter(tagAdapter);

        tagFlowLayout.setOnSelectListener(new TagFlowLayout.OnSelectListener() {
            @Override
            public void onSelected(Set<Integer> selectPosSet) {

            }
        });


        test();

    }



    public void test() {
        List<String> list = new ArrayList<>();
        list.add("散货");
        list.add("20千克/箱");
        list.add("40公斤/盒");
        list.add("50个/盒");
        list.add("10公斤/袋");
        updateTag(list);
    }


    public void updateTag(List<String> list) {
        this.list.clear();
        if (list != null) {
            this.list.addAll(list);
        }
        tagAdapter.notifyDataChanged();
    }

    @Override
    public void onRightClick() {
        finish();
    }

    @Override
    public void onClick(View view) {
        super.onClick(view);
        switch (view.getId()) {

            case R.id.rightbtn:

                break;


        }
    }

    private void save() {



        Intent intent = new Intent();
//        intent.putExtra("packageSize",edPackage.getText().toString());
//        intent.putExtra("unit",packageUnit);
//        intent.putExtra("container",packageContainer);
//        intent.putExtra("weight",edWeight.getText().toString());

        setResult(RESULT_OK, intent);
        finish();
    }





}
